package com.isoft.controller;
import com.isoft.pojo.Save;
import com.isoft.view.BankSystemMenu;
import java.io.IOException;
import java.util.HashMap;
import java.util.Scanner;
/**
 * @Author:老张
 * @Date:2024/8/28 14:48
 * @Description:
 **/

public class BankSystem {
    HashMap<String, Save> bankdb;//String 键：唯一,Save 储户信息
    Scanner input;
    public BankSystem() {//构造函数,作用初始化数据成员
        bankdb = new HashMap<>();
        input = new Scanner(System.in);
    }
    public void runBankSystem() throws IOException {//ctrl+alt+l 格式化

        String flags = "N";
        do {
            BankSystemMenu.showMenu();
            String userInput = input.next();
            switch (userInput) {
                case "1" -> { //不用 Break，jdk14 以上
                    createAccount();//ctrl+鼠标左键
                }
                case "2" -> {
                    deleteAccount();
                }
                case "3" -> {
                    saveMoney();
                }
                case "4" -> {
                    getMoney();
                }
                case "5" -> {
                    changeMoney();
                }
                case "6" -> {
                    showBalance();
                }
                case "7" -> {
                    exit();
                }
                default -> {
                    System.out.println("您输入有误！请重试！");
                }
            }
            System.out.println("是否继续操作本系统?(Y|N)");
            flags = input.next();
            BankSystemMenu.clearScreen();//清屏
        } while (flags.equalsIgnoreCase("y"));
        System.out.println("欢迎下次再来！！");
    }
    //开户
    public void createAccount() {
        System.out.println("正在创建账户...");
        System.out.print("请输入用户名:");
        String name=input.next();
        System.out.print("请输入密码:");
        String pwd=input.next();
        System.out.print("请输入性别:");
        String gender=input.next();
        Save save = new Save();
        String accountid="6226"+(int)(1000+(Math.random()*9000));
        System.out.println("已为您生成一个专属卡号："+accountid);
        save.setAccountid(accountid);
        save.setName(name);
        save.setPwd(pwd);
        save.setGender(gender);
        bankdb.put(accountid,save);//银行账号
        System.out.println("您已经开户完成");
        System.out.println("您的开户信息："+bankdb);
    }
    //存款
    public void saveMoney() {
    }
    //取款
    public void getMoney() {
    }
    //转账
    public void changeMoney() {
    }
    public void showBalance() {
        System.out.println("查询余额");
    }
    //销户
    public void deleteAccount() {
        System.out.println("删除账户");
    }
    //退出系统
    public void exit() {
    }
}
